<template>
  <div class="recharge">
    <NavBar title="我的钱包" />
    <div class="user-data">
      <div class="user-data-item">
        <span>总资产(元)</span>
        <span>{{ (amount / 100).toFixed(2) }}</span>
      </div>
      <div class="user-data-item" @click="$router.push('/coupon')">
        <span>累计充值(元)</span>
        <span>{{ oldamount }}</span>
      </div>
      <div class="user-data-item">
        <span>累计消费(元)</span>
        <span>{{ iamount }}</span>
      </div>
    </div>
    <van-row type="flex" justify="center">
      <van-col span="22">
        <van-cell title="充值¥100赠送¥10" icon="shop-o">
          <!-- 使用 right-icon 插槽来自定义右侧图标 -->
          <template #right-icon>
            <van-button type="danger" round size="mini" @click="toAccount">充值</van-button>
          </template>
        </van-cell>
        <van-cell title="充值¥1赠送¥1000" icon="shop-o">
          <!-- 使用 right-icon 插槽来自定义右侧图标 -->
          <template #right-icon>
            <van-button type="danger" round size="mini"  @click="toAccount2">充值</van-button>
          </template>
        </van-cell>
      </van-col>
    </van-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      amount: 0,
      oldamount: 0,
      iamount: 0
    }
  },
  methods: {
    async loadData () {
      // 余额
      const { data: resamount } = await this.$post(this.API.API_URL_CUSTOMER_Account, {
        userId: localStorage.getItem('userId')
      })
      this.amount = resamount.amount
      // 累计充值
      /* const { data: resoldamount } = await API.shopAPI.get('account/rechargeLog', {
        userId: localStorage.getItem('userId')
      })
      console.log(resoldamount) */
    },
    async toAccount () {
      const { data: res } = await this.$post(this.API.API_URL_CUSTOMER_Recharge_Account, {
        userId: localStorage.getItem('userId'),
        amount: 11000
      })
      if (res) {
        this.$toast('充值成功')
        this.loadData()
      } else {
        this.$toast('充值失败')
      }
    },
    async toAccount2 () {
      const { data: res } = await this.$post(this.API.API_URL_CUSTOMER_Recharge_Account, {
        userId: localStorage.getItem('userId'),
        amount: 100100
      })
      if (res) {
        this.$toast('充值成功')
        this.loadData()
      } else {
        this.$toast('充值失败')
      }
    }
  },
  created () {
    this.loadData()
  }
}
</script>

<style lang="less" scoped>
  .user-data {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    font-size: 14px;
    margin: 0 auto 10px;
    padding: 10px 0;
    width: 90%;
    background: rgba(0, 0, 0, 1.0);
    border-radius: 5px;
    .user-data-item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 33.33%;
      color: #deb162;
      line-height: 18px;
    }
  }
  .van-cell__title {
    text-align: left;
    margin-left: 8px;
  }
  .van-button {
    padding: 0 9px;
  }
</style>
